<div class="sort_menu">
    <a href="#" title="Do not sort by status" onclick="showSmon('not_sort')">Do not sort</a> |
    <a href="#" id="sort_by_status" title="Sort by status" onclick="sort_by_status()">Sort by status</a> |
    <a href="#" title="SMOM Dashboard - Roxy-WI" onclick="showSmon('refresh');">Refresh</a>
    <span style="padding-left: 20px;">
		{% set down = [] %}
		{% set up = [] %}
		{% set dis = [] %}
		{% for s in smon %}
			{% if s.en == 1 %}
				{% if s.status == 1 and s.http_status == 1 and s.body_status == 1 %}
					{% if  up.append('1') %} {% endif %}
				{% else %}
					{% if  down.append('1') %} {% endif %}
				{% endif %}
			{% else %}
				{% if  dis.append(s.group) %} {% endif %}
			{% endif %}
		{% endfor %}
		<b>Status summary: UP: {{up|length}}, DOWN: {{down|length}}, Disabled: {{dis|length}}</b>
	<span>
</div>
{% set group = [] %}
{% set group_prev = [] %}
{%- for s in smon -%}
    {% if s.group %}
        {% if s.group not in group %}
        <div class="smon_group">
            <div class="group_name">
                {{ s.group }}
            </div>
        </div>
        {% endif %}
        {% if group.append(s.group) %} {% endif %}
    {% else %}
         <div class="smon_group">
            <div class="group_name">
                None
            </div>
        </div>
    {% endif %}
    {% if s.en == 1 %}
        {% if s.status == 1 and s.http_status == 1 and s.body_status == 1 %}
            <div class="smon_services good div-server-head-up"
        {% else %}
            <div class="smon_services err div-server-head-down"
        {% endif %}
    {% else %}
        <div class="smon_services dis div-server-head-dis"
    {% endif %}
       title="Enabled checks:
Port check{% if s.http %},
HTTP status check: {{s.http.split(':')[0]}}://{{s.ip}}:{{s.port}}{{s.http.split(':')[1]}}
{% if s.body and s.body is not none %}, Body response check: {{s.body}}{% endif %}
{% endif %}">
    <div class="ip">
        {% if s.ip|string|length > 23 %}
            <span style="font-size: 11px;">
        {% elif s.ip|string|length > 20 %}
            <span style="font-size: 12px;">
        {% elif s.ip|string|length > 17 %}
            <span style="font-size: 15px;">
        {% else %}
            <span>
        {% endif %}
                <a href="smon.py?action=history&host={{s.ip}}" title="View history for {{s.ip}} host" class="link">{{s.ip}}:{{s.port}}</a>
            </span>
        </span>
    </div>
    <div class="desc">
        {% if s.desc is not none %}
            <b>{{s.desc}}</b>
        {% else %}
            Desc: None
        {% endif %}
    </div>
    <div class="desc">
        {% if s.en == 1 %}
            {% if s.status == 1 and s.http_status == 1 and s.body_status == 1 %}
                Uptime: <time class="timeago" datetime="{{s.time_state}}">{{s.time_state}}</time>
            {% elif s.status == 0 or s.http_status == 0 or s.body_status == 0 %}
                Downtime: <time class="timeago" datetime="{{s.time_state}}">{{s.time_state}}</time>
            {% else %}
                Uptime: N/A
            {% endif %}
        {% else %}
            Uptime: N/A
        {% endif %}
    </div>
    <div class="res_time">
        {% if s.en == 1 %}
            {% if s.status == 1 %}
                Resp time:
            {% else %}
                Last resp time:
            {% endif %}
            {% if s.responce_time %}
                <span title="{{s.responce_time}} ms">{{s.responce_time|truncate(9)}} ms</span>
            {% else %}
                N/A
            {% endif %}
        {% else %}
            N/A
        {% endif %}
    </div>
    {% if s.en == 1 %}
         {% if s.status == 1 and s.http_status == 1 and s.body_status == 1 %}
            <div class="up">
                <center>
                    UP
                </center>
            </div>
         {% elif s.http_status == 0 %}
            <div class="down">
                 <center style="padding-top: 7px;">
                      HTTP FAILURE
                 </center>
            </div>
         {% elif s.body_status == 0 %}
            <div class="down">
                 <center style="padding-top: 7px;">
                      BODY FAILURE
                 </center>
            </div>
         {% elif s.status == 3 %}
            <div class="unknown">
                <center style="padding-top: 7px;">
                    UNKNOWN
                </center>
            </div>
         {% else %}
            <div class="down">
                <center style="padding-top: 7px;">
                    PORT DOWN
                </center>
            </div>
         {% endif %}
    {% else %}
        <div class="disable">
            <center>
                Disabled
            </center>
        </div>
    {% endif %}
    </div>
{% endfor %}
<script>
    jQuery(document).ready(function() {
        jQuery("time.timeago").timeago();
    })
    {% if sort == 'by_status' %}
        sort_by_status();
    {% endif %}
</script>